using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;

namespace BUS
{
   public class tbsanphamBUS
    {
        static public string error = "";
        public static int  Insert(tbsanphamDTO sp)
        {
            tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
            return tbsanphamDAL.Insert(sp);
        }
       public static void Update(tbsanphamDTO sp)
        {
            tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
            tbsanphamDAL.Update(sp);
            error = tbsanphamDAL.error;
        }
        public static void Delete(int iD)
        {
            tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
            tbsanphamDAL.Delete(iD);
        }
        public static tbsanphamcollection GET(string Where, int PageIndex, int PageSize,
                                        string OrderBy, string OrderDirection,
                                        out int TotalRecords)
        {
            tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
            return tbsanphamDAL.GET(Where, PageIndex, PageSize,
                            OrderBy, OrderDirection, out TotalRecords);
        }
       public static tbsanphamDTO GetByID(int iD)
       {
           int t = 0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           tbsanphamcollection spcolect = tbsanphamDAL.GET("where " + tbsanphamcolumn.Masp.ToString() + " = " + iD.ToString(), 0, 0,
               tbsanphamcolumn.Tensp.ToString(), "ASC", out t);
           if (spcolect.Count == 1)
               return spcolect[0];
           return null;
           
       }
       public static tbsanphamcollection GETAll()
       {
           int t = 0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           return tbsanphamDAL.GET("where 1=1", 0, 10, tbsanphamcolumn.Tensp.ToString(), "ASC", out t);
       }
       public static tbsanphamcollection getidDN(int id)
       {
           int t =0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           return tbsanphamDAL.GET("where " + tbsanphamcolumn.Madn.ToString() + " = " + id.ToString(), 0, 0,
               tbsanphamcolumn.Madn.ToString(), "ASC", out t);
       }
       public static tbsanphamcollection gettentheotensp(string ten,int ID)
       {
           int t = 0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           return tbsanphamDAL.GET("where " + tbsanphamcolumn.Tensp.ToString() + " LIKE N'%" + ten + "%' AND "+tbsanphamcolumn.Madn.ToString()+"="+ID.ToString(), 0, 0,
               tbsanphamcolumn.Madn.ToString(), "ASC", out t);
       }
       public static tbsanphamcollection getidtinhthanh(int id)
       {
           int t = 0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           return tbsanphamDAL.GET("where " + tbsanphamcolumn.Matinhthanh.ToString() + " = " + id.ToString(), 0, 0,
               tbsanphamcolumn.Masp.ToString(), "ASC", out t);
       }
       public static tbsanphamcollection getloai(int id)
       {
           int t = 0;
           tbsanphamDAL tbsanphamDAL = new tbsanphamDAL();
           return tbsanphamDAL.GET("where " + tbsanphamcolumn.Maloaisp.ToString() + " = " + id.ToString(), 0, 0,
               tbsanphamcolumn.Masp.ToString(), "ASC", out t);
       }
    }
}
